package com.bd.scm.module.uploadFile.controller;

import com.alibaba.fastjson.JSONObject;
import com.bd.scm.module.enums.UploadTypeEnum;
import com.bd.scm.module.uploadFile.service.UploadFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Mason
 * @version 1.0
 * @since 2020/1/4 9:04
 */
@RestController
@RequestMapping("uploadFile")
public class UploadFileController {

    @Autowired
    private UploadFileService uploadFileService;


    @PostMapping("upload")
    @ResponseBody
    public JSONObject upload(HttpServletRequest request, @RequestParam("file") MultipartFile file) {
        JSONObject res = new JSONObject();

        //保存的文件名
        String resStr = uploadFileService.saveTempFile(file);
        res.put("success",true);
        res.put("fileName",resStr);
        return res;
    }
}
